package com.uniqueyi.baselib.utilsbase.net;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;

/**
 * Created by
 * author:  weiyi.
 * date:    2017/12/28.  1:20.
 * prj:     crxl.
 * <p>
 * <p>
 * 使用方式
 * 记得在manifest中注册
 * <receiver android:name="cn.broadcastreceiver.NetBroadcastReceiver" >
 * <intent-filter>
 * <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
 * </intent-filter>
 * </receiver>
 */

public class NetBroadcastReceiver extends BroadcastReceiver {

    private static NetEvevt evevt;

    public static void setEvevt(NetEvevt et) {
        evevt = et;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        // TODO Auto-generated method stub
        // 如果相等的话就说明网络状态发生了变化
        if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)) {
            int netWorkState = NetUtils.getNetWorkState(context);
            // 接口回调传过去状态的类型
            evevt.onNetChange(netWorkState);
        }
    }

    // 自定义接口
    public interface NetEvevt {
        public void onNetChange(int netMobile);
    }
}
